package gui;

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

import physics.Forcer;
import physics.PhysicsEngine;

public abstract class Menu<E> extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JList forcers = new JList();
	public Menu() {
		setLayout(new BorderLayout());
		add(forcers);
		refresh();
		JPanel bottom = new JPanel();
		bottom.setLayout(new FlowLayout());
		JButton add = new JButton("Add");
		add.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				add();
				refresh();
			}
		});
		JButton edit = new JButton("Edit");
		edit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				E selectedObj = (E) forcers.getSelectedValue();
				System.out.println(selectedObj);
				edit(selectedObj);
			}
		});
		JButton remove = new JButton("Remove");
		remove.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				E selectedObj = (E) forcers.getSelectedValue();
				remove(selectedObj);
			}
		});
		bottom.add(add);
		bottom.add(edit);
		bottom.add(remove);
		add(bottom,BorderLayout.SOUTH);
	}
	protected abstract void add();
	protected abstract void edit(E e);
	protected abstract void remove(E e);
	protected void refresh() {
		forcers.setListData(getThings());
	}
	protected abstract E[] getThings();
}
